package com.ekeyman.securecreditlib.domain;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

@Entity
@Table(name = "REGISTRY")
public class Registry implements Serializable {
	private static final long serialVersionUID = 3903549640115127166L;
	private long id;
	private String publicKey;
	private String privateKey;
	private String clearSafetyword;;
	private String cipherSafetyword;
	
	private long version;

	
	public void setId(long id) {
		this.id = id;
	}
	
	@Id @GeneratedValue
	public long getId() {
		return id;
	}
	
	public void setVersion(long version) {
		this.version = version;
	}
	
	@Column(name="VERSION")
	public long getVersion() {
		return version;
	}

	public void setPublicKey(String publicKey) {
		this.publicKey = publicKey;
	}

	@Column(name="PUBLICKEY", nullable=false)
	public String getPublicKey() {
		return publicKey;
	}

	public void setPrivateKey(String privateKey) {
		this.privateKey = privateKey;
	}

	@Column(name="PRIVATEKEY", nullable=false)
	public String getPrivateKey() {
		return privateKey;
	}

	public void setClearSafetyword(String clearSafetyword) {
		this.clearSafetyword = clearSafetyword;
	}

	@Column(name="CLEARSAFETYWORD")
	public String getClearSafetyword() {
		return clearSafetyword;
	}
	
	public void setCipherSafetyword(String cipherSafetyword) {
		this.cipherSafetyword = cipherSafetyword;
	}

	@Column(name="CIPHERSAFETYWORD")
	public String getCipherSafetyword() {
		return cipherSafetyword;
	}

	@Transient
	@Override
	public boolean equals(Object o){
		boolean result = false;
		if (o instanceof Registry){
			Registry cc = (Registry)o;
			if(getPublicKey().equalsIgnoreCase(cc.getPublicKey()) &&
					getPrivateKey().equalsIgnoreCase(cc.getPrivateKey())) {
				result = true;
			}
		}
		return result;
	}

	@Transient
	@Override
	public int hashCode(){
		return getPublicKey().hashCode() +
			getPrivateKey().hashCode();
	}
}
